package fun.yyds.repository;


import fun.yyds.entity.es.EsLogDocument;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

import java.util.List;

/**
 * @description: ESLogService
 * @author: Chensn
 * @time: 2024/10/31
 */
public interface EsLogMapper extends ElasticsearchRepository<EsLogDocument, String> {

    @Query("{\"match\": {\"message\": \"?0\"}}")
    List<EsLogDocument> findByMessage(String message);

    @Query("{\"range\": {\"@timestamp\": {\"gte\": \"?0\", \"lte\": \"?1\"}}}")
    List<EsLogDocument> findByTimestampRange(String startTime, String endTime);

    /**
     * 模糊查询--分页
     *
     * @param process
     * @param pageable
     * @return
     */
    @Query("{\"fuzzy\": {\"message\": {\"value\": \"?0\", \"fuzziness\": \"AUTO\"}}}")
    Page<EsLogDocument> findByMessageWithFuzzy(String process, Pageable pageable);

    @Query("{\"fuzzy\":{\"message\":{\"value\":\"?0\",\"fuzziness\":\"AUTO\"}}}")
    List<EsLogDocument> findFuzzyLogsByMessage(String process, String orderBy);

}